<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>配件信息管理</title>
    <script src="../js/jquery.min.js"></script>
    <script src="../js/jquery.easyui.min.js"></script>
    <script src="../js/easyui-lang-zh_CN.js"></script>
    <link rel="stylesheet" href="../themes/icon.css">
    <link rel="stylesheet" href="../themes/default/easyui.css">
    <link rel="stylesheet" href="../css/wu.css">
    <style type="text/css">
        .subck { display:none }/*合计单元格样式*/
    </style>
    <script>
        var  selectIndex = -1;

        function hideTable(){
            $("#searchdiv").toggle();
        }
        function openpartdetail(){
            self.parent.addTabs('增加配件信息','goods/addPartDetail.jsp');
            self.parent.$("#jxc_tabs").tabs("close","配件信息管理");
        }
        
        function reloaddata(){
        	$("#form1").form('reset');
			$("#productList").datagrid('load',{});
        }
        
        $(function(){
            //添加下拉框
            $('#cc').combobox({    
			    url:'/kxmanage/instroageBill/getPartTypeList.json',    
			    valueField:'id',    
			    textField:'typeName'   
			});
            //数据表格
            $("#productList").datagrid({
                fit:true,
                url:'/kxmanage/part/getPartDetailList.json',
                rownumbers:false,
                pageNumber:1,
                pageSize:5,
                pageList:[5,10,15],
                checkOnSelect:false,
                columns:[[
                    {field:'ck',checkbox:true},
                    {field:'code',title:'配件编码',width:160},
                    {field:'partNo',title:'件号',width:100},
                    {field:'currPartNo',title:'通用件号',width:100},
                    {field:'typeName',title:'配件类别',width:60},
                    {field:'partName',title:'配件名称',width:150},
                    {field:'partBrand',title:'配件品牌',width:60},
                    {field:'mold',title:'配件型号',width:100},
                    {field:'sellPrice',title:'配件销售价格',width:90},
                    {field:'dispalyer',title:'显示状态',width:60,
                        formatter:function (value,row,index) {
                            if(row.displayer==1){
                                return "显示";
                            }else{
                                return "隐藏";
                            }
                        }
                    },
                    {field:'userName',title:'操作员',width:60},
                    {field:'memo',title:'备注',width:100},
                    {field:'opt',title:'操作',width:100,
                        formatter:function (value,row,index) {
                            var context="<a href=\"javascript:modifyPartDetail('"+row.code+"')\">修改</a>&nbsp;&nbsp;" +
                                "<a href=\"javascript:delrow('"+row.code+"')\">删除</a>"
                            return context;
                        }
                     }
                ]],
                toolbar:'#wu_toolbar',
                showFooter:true,
                pagination:true //向后台传递参数page 和rows
            })
            
        $("#search_btn").click(function(){
            $("#productList").datagrid('load',serializeJson())
        }) 
        
        });
        function detail(id) {
            $.messager.alert("信息","查看"+id+"产品详情");
        }
        function modifyPartDetail(code) {
            parent.addTabs("修改配件信息","../part/modifyPartDetail.html?code="+code);
            self.parent.$("#jxc_tabs").tabs("close","配件信息管理");
        }
        function addProduct() {
            parent.addTabs("添加产品","goods/add_goods.html");
        }
        function delrow(code){
             $.messager.confirm('确认','您确认想要删除记录吗？',function(r){
                if (r){
                    $.post("/kxmanage/part/delrows.json",{"codes":code},resultDel);
                }
            });
        }
        function resultDel(data){
            if(data.result=='success'){
            	$("#billDetails").hide();
                $.messager.alert('消息'," 删除成功！");
                $("#productList").datagrid('load',{});
            }else{
                $.messager.alert('消息'," 删除失败！");
            }
        }
        //删除
        function deleteRightGridRow(rowId){    	
	        var datas = $("#productList").datagrid('getData');    	
	        for(var i=0;i<datas.rows.length;i++){    	    
		        if(datas.rows[i].id==rowId){//数据中的id和渲染时的id相等    	    	
		            //通过传入的id值查询到对应的记录，在获取实际的Index,这样去删除,（直接传入渲染好的索引值会出现错误）		  		
			        var rowIndex = $("#productList").datagrid('getRowIndex',datas.rows[i]);		  		 
			        $("#productList").datagrid('deleteRow', rowIndex);		  		 
			        return;    		
		        }   		 
	        } 
         }
       
        function del() {
            var rows=$("#productList").datagrid('getSelections');
            if(rows.length==0){
                $.messager.alert('消息',"请选择记录");
                return
            }
            $.messager.confirm('确认','您确认想要删除记录吗？',function(r){
                if (r){
                    var ids=[]
                    for( var  i=0;i<rows.length;i++){
                        ids.push(rows[i].code);
                    }
                    $.post("/kxmanage/instroageBill/delrows.json",{"codes":ids},resultDel);
                }
            });
        }
       //表单序列化
        function serializeJson(){  
            var serializeObj={};  
            var array=$("#form1").serializeArray();  
            var str=$("#form1").serialize();  
            $(array).each(function(){  
                if(serializeObj[this.name]){  
                    if($.isArray(serializeObj[this.name])){  
                        serializeObj[this.name].push(this.value);  
                    }else{  
                        serializeObj[this.name]=[serializeObj[this.name],this.value];
                    }  
                }else{  
                    serializeObj[this.name]=this.value;   
                }  
            });  
                return serializeObj;  
            }; 
        //指定列求和
        function compute(colName) {
			var rows = $('#productList').datagrid('getRows');
			var total = 0;
			for (var i = 0; i < rows.length; i++) {
				total += parseFloat(rows[i][colName]);
			}
			return total;
		}
		function onLoadSuccess() {
			//添加“合计”列
			$('#table').datagrid('appendRow', {
				Saler: '<span class="subtotal">合计</span>',
				TotalOrderCount: '<span class="subtotal">' + compute("TotalOrderCount") + '</span>',
				TotalOrderMoney: '<span class="subtotal">' + compute("TotalOrderMoney") + '</span>',
				TotalOrderScore: '<span class="subtotal">' + compute("TotalOrderScore") + '</span>',
				TotalTrailCount: '<span class="subtotal">' + compute("TotalTrailCount") + '</span>',
				Rate: '<span class="subtotal">' + ((compute("TotalOrderScore") / compute("TotalTrailCount")) * 100).toFixed(2) + '</span>'
			});
		}
    </script>
</head>
<body>
<div id="wu_toolbar">
    <div class="wu_toolbar_button" style="background-color:#CEDFEF;">
        <a  href="#" onclick="hideTable()" class="easyui-linkbutton" data-options="iconCls:'icon-search'" plain="true"> 查询</a>|
        <a  href="#" onclick="openpartdetail()" class="easyui-linkbutton" data-options="iconCls:'icon-add'" plain="true">增加</a>|
        <a  href="#" onclick="reload()" class="easyui-linkbutton" data-options="iconCls:'icon-communication'" plain="true"> 导出excal</a>
    </div>
    <div id="searchdiv" style="display: block;width: 100%;">
        <form name="form1" id="form1">
             <table width="100%" border="0" cellspacing="0" style="background-color:#C9DFFF;border-top:1px solid white;" >
                <tbody><tr>
                    <td width="70"><b>检索条件:</b></td>
                    <td width="70" align="right">型号:</td>
                    <td width="100" align="left"><input name="mold" class="easyui-textbox" style="height:25px;" type="text" id="mold" value="" maxlength="100"></td>
                    <td width="70" align="right">件号:</td>
                    <td width="100" align="left"><div class="l-text-wrapper"><div class="l-text l-text-date"><input name="partNo" style="height:25px;" id="code" value=""  class="easyui-textbox" ><div class="l-text-l"></div><div class="l-text-r"></div><div class="l-trigger"><div class="l-trigger-icon"></div></div></div></div></td>
                             <td width="70" align="right">名称:</td>
                    <td width="100" align="left"><input name="partName" class="easyui-textbox" style="height:25px;" type="text" id="name" value="" maxlength="100"></td>
                    <td width="70" align="right">类别:</td>
                    <td width="100" align="left">
                        <select id="cc" class="easyui-combobox" name="partTypeId" style="width:150px;height:25px;">   
						      
						</select> 
                    </td>
                    <td width="72">
                        <a id="search_btn" href="#" class="easyui-linkbutton" style="height:25px;" data-options="iconCls:'icon-search'">搜索</a>
                    </td>
                    <td width="72">
                        <a id="reset_btn" href="#" class="easyui-linkbutton" style="height:25px;" onclick="reloaddata()" data-options="iconCls:'icon-refresh'">重置</a>
                    </td>
                    <td width="0"></td>
                </tr>
                </tbody>
            </table>
            <input type="hidden" id="menuCode" value="100001001">
        </form>
    </div>
</div>
<div id="productList" class="easyui-datagrid">

</div>
<div id="billDetails">
    <div id="billCode" style="font-weight:bolder;font-size:14px;"></div>
    <div id="billDetailList" class="easyui-datagrid">
      
    </div>
</div>
            

</body>
</html>